<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生新增</title>
</head>
<body>

<div>
    <input type="hidden" id="id">
    <div>
        <label>
            姓名：<input type="text" id="name">
        </label>
    </div>
    <div>
        <label>
            性别：<input type="radio" name="sex" value="1" checked>男<input type="radio" name="sex" value="2">女
        </label>
    </div>

    <div>
        <label>
            年龄：<input type="text" id="age">
        </label>
    </div>

    <div>
        <label>
            大学：<input type="text" id="edu">
        </label>
    </div>

    <div>
        <label>
            学号：<input type="text" id="no">
        </label>
    </div>

    <div>
        <label>
            城市：
            <select name="" id="city">
                <option value="1">北京</option>
                <option value="2">福州</option>
                <option value="3">厦门</option>
                <option value="4">龙岩</option>
                <option value="5">泉州</option>
            </select>
        </label>
    </div>
    <div>
        <button onclick="addClick()">提交</button>
    </div>
</div>
<script src="ajax.js"></script>
<script>
    function addClick() {
        add();
    }

    function showRes(jsonObj) {
        window.location.href = "/StudentList.html"
    }

    function add() {
        let nameStr = document.getElementById("name").value;//名字
        let sexStr = document.getElementsByName("sex");
        let ageStr = document.getElementById("age").value;//年龄
        let eduStr = document.getElementById("edu").value;//大学
        let cityObj = document.getElementById("city");
        let cityStr = cityObj.value;//城市
        let numStr = document.getElementById("no").value;
        let formData = new FormData();//表单数据对象，即键值对
        formData.append("name", nameStr);
        formData.append("sex", sexStr);
        formData.append("age", ageStr);
        formData.append("edu", eduStr);
        formData.append("city", cityStr);
        formData.append("no", numStr);
        ajax("/student/add.php", "POST", formData, showRes);

    }

</script>
</body>
</html>